package com.tju.welding.dao;

import com.tju.welding.pojo.User;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

@Mapper
@Component
public interface UserMapper {

        @Insert("INSERT INTO user (password, real_name, phone_number, user_type)"
                        + " VALUES(#{password}, #{real_name}, #{phone_number}, #{user_type})")
        int addUser(@Param("password") String password, @Param("real_name") String realName,
                        @Param("phone_number") String phoneNumber, @Param("user_type") int userType);

        @Select("SELECT * FROM user WHERE phone_number = #{phone_number}")
        User getUserByPhoneNumber(@Param("phone_number") String phoneNumber);

        @Select("SELECT * FROM user WHERE user_id = #{user_id}")
        User getUserByUserId(@Param("user_id") int userId);

        @Select("SELECT user_id FROM user WHERE phone_number = #{phone_number}")
        int getUserIdByPhoneNumber(@Param("phone_number") String phoneNumber);

        @Select("SELECT password FROM user WHERE phone_number = #{phone_number}")
        String getPasswordByPhoneNumber(@Param("phone_number") String phoneNumber);

}
